#include<bits/stdc++.h>
using namespace std;
pair<int,int> period[100005];
int photop[100005],lp=0,T,n,m,L,V,i;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--)
    {
        int Goal_A=1,Goal_B=1,Goal_C=1;
        cin>>n>>m>>L>>V;
        for(i=1;i<=n;i++)
        {
            int d,v,a;
            cin>>d>>v>>a;
            if(a<=0) Goal_B=0;
            if(a!=0) Goal_A=0;
            if(a>=0) Goal_C=0;
        }
        cin>>m;
        for(i=1;i<=m;i++) cin>>photop[i];
        if(Goal_A==1||Goal_B==1) {cout<<1<<endl; continue;}
    }
    return 0;
}
